<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/1/24
 * Time: 下午9:06
 */

//用来对循环的事件进行迭代。向它传入开始时间、结束时间和间隔区间，会得到这其中所有的事件。

$start = new DateTime();
$end = (new DateTime())->add(new DateInterval("P1Y"));
// output all thursdays between $start and $end
$periodInterval = DateInterval::createFromDateString('first thursday');
$periodIterator = new DatePeriod($start, $periodInterval, $end,
    DatePeriod::EXCLUDE_START_DATE);
foreach ($periodIterator as $date) {
    // output each date in the period
    echo $date->format('Y-m-d') . PHP_EOL;
}


//---------------------------------------------------------------------------------------------

$i = new DateInterval('P1D');
echo $i->format("%d day").PHP_EOL;
$i = DateInterval::createFromDateString('1 day');
echo $i->format("%d day").PHP_EOL;
$i = DateInterval::createFromDateString('2 months');
echo $i->format("%m months").PHP_EOL;
$i = DateInterval::createFromDateString('12 years');
echo $i->format("%Y years").PHP_EOL;
$i = DateInterval::createFromDateString('second years + first month');
echo $i->format("%Y years %m month").PHP_EOL;
